Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a global hook for OpenSumi DevTools to communicate with #1560

Merged
merged 27 commits into from
Aug 25, 2022

Conversation

tyn1998
Copy link
Member

@tyn1998 tyn1998 commented Aug 22, 2022

This PR will resolve #1098. You are welcomed to visit the issue to review the whole process of how the devtools developed.

Types

  • 🎉 New Features

Background or solution

A global hook

Q: How opensumi/core and opensumi-devtools communicate with each other?
A: A global hook! That is the key.

Step 1. opensumi/core exposes a global hook window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__ = {} when ClientApp starts.

Step 2. opensumi-devtools tries to detect the existence of the hook, if the hook exists it will run.

Step 3. if users click "startCapture" button in the devtools, a few variables and functions will be injected to the hook by the API chrome.devtools.inspectedWindow.eval().

Step 4. when messages are received and sended in proxy.ts, opensumi/core will try to access to window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.capture, if accessible, it will call the injected global capture function and then put messages to window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.messages.

Step 5. opensumi-devtools get new messages from window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.messages every 1 second and set the message array to empty after getting all new messages.

Step 6. opensumi-devtools present the messages with a good UI.

Step 7. if users click "stopCapture" button, window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__ will be set to {} so no capture function can be accessed and opensumi/core will stop sharing its messages.

A contribution point

Q: As an extension, how opensumi-devtools get network latency from opensumi/core?
A: In the same way as how messages are captured.

Step 1. by leveraging opensumi's lifecycle contribution, I set an event listener window.addEventListener('devtools:latency', ()=>{...}) in initialize phase.

Step 2. if users click startCapture button, the custom event "devtools:latency" with "start" command will be dispatched. opensumi/core will start to test rtt after receiving the event and put the value to window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.latency.

Step 3. opensumi-devtools will get latency value from the hook and presents it in UI.

Changelog

a global hook and a contribution point for OpenSumi DevTools to communicate with.

@tyn1998 tyn1998 changed the title feat: for ASoC2022 chrome devtools feat: a global hook for OpenSumi DevTools to communicate with Aug 22, 2022
@codecov
Copy link

codecov bot commented Aug 22, 2022

Codecov Report

Merging #1560 (29ff670) into main (c26945d) will decrease coverage by 0.20%.
The diff coverage is 80.35%.

@@            Coverage Diff             @@
##             main    #1560      +/-   ##
==========================================
- Coverage   57.87%   57.66%   -0.21%     
==========================================
  Files        1251     1252       +1     
  Lines       77996    78146     +150     
  Branches    16275    16319      +44     
==========================================
- Hits        45139    45062      -77     
- Misses      29919    30124     +205     
- Partials     2938     2960      +22     
Flag Coverage Δ
jsdom 52.44% <55.35%> (-0.07%) ⬇️
node 15.78% <66.07%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/connection/src/node/connect.ts 100.00% <ø> (ø)
...kages/addons/src/browser/connection-rtt-service.ts 71.42% <71.42%> (ø)
packages/connection/src/common/proxy.ts 83.56% <74.19%> (-2.16%) ⬇️
packages/connection/src/common/utils.ts 94.44% <92.85%> (-5.56%) ⬇️
packages/addons/src/browser/index.ts 100.00% <100.00%> (ø)
packages/core-browser/src/bootstrap/app.ts 64.77% <100.00%> (+0.11%) ⬆️
packages/core-browser/src/logger/browser-logger.ts 36.00% <0.00%> (-40.00%) ⬇️
packages/logs-core/src/node/log.service.ts 22.22% <0.00%> (-38.89%) ⬇️
packages/editor/src/browser/doc-model/save-task.ts 84.00% <0.00%> (-16.00%) ⬇️
...xtension/src/hosted/api/vscode/env/ext.host.env.ts 61.90% <0.00%> (-9.53%) ⬇️
... and 36 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tyn1998
Copy link
Member Author

tyn1998 commented Aug 22, 2022

@yantze @erha19 @bytemain

Hi guys! Please take minutes to review the code, thanks!

@tyn1998
Copy link
Member Author

tyn1998 commented Aug 22, 2022

对于Web端,只要浏览器安装了opensumi devtools插件即可生效;对于Electron端,需要等该插件上架到chrome webstore后再利用electron-devtools-installer进行集成(见此issue)。

所以不想分好几个PR的话,可以等到插件发布上架后再合并这个PR。

packages/connection/src/common/proxy.ts Outdated Show resolved Hide resolved
packages/connection/src/common/proxy.ts Outdated Show resolved Hide resolved
@tyn1998 tyn1998 force-pushed the feat/for-asoc-chrome-devtools branch from 6b19cb4 to 29ff670 Compare August 24, 2022 14:08
Copy link
Member

@erha19 erha19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erha19 erha19 merged commit 4dcabf6 into opensumi:main Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASoC 2022: Implement a Chrome DevTools for viewing OpenSumi communication messages
3 participants